﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Inspired.Euler
{
    /// <summary>
    /// A palindromic number reads the same both ways. The largest palindrome made from the 
    /// product of two 2-digit numbers is 9009 = 91 x 99.
    /// 
    /// Find the largest palindrome made from the product of two 3-digit numbers.
    /// </summary>
    public static class Problem004
    {
        /// <summary>
        /// Find the largest palindrome made from the product of two 3-digit numbers.
        /// </summary>
        [EulerProblem(4, Title = "Find the largest palindrome made from the product of two 3-digit numbers.")]
        public static long Solve()
        {
            List<int> palindromes =
                Enumerable.Range(100, 899).SelectMany(i => 
                Enumerable.Range(100, 899), (a, b) => a * b)
                    .Where(i => i.IsPalindrome(10))
                    .ToList();

            return palindromes.Max();
        }
    }
}
